home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Toolbox / ProgressBars 1.0 / Sources / Windows.c < prev   
Encoding:
C/C++ Source or Header  |  1996-09-17  |  3.0 KB  |  188 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Windows.c
  3.  
  4.     Contains:    Handle application's windows
  5.  
  6.     Written by:    Chris White, Developer Technical Support
  7.     
  8.     Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Change History (most recent first):
  11.     
  12.             1/22/96            CW        First release
  13.  
  14. */
  15.  
  16.  
  17.  
  18. #pragma segment Core
  19.  
  20.  
  21.  
  22. // System Includes
  23.  
  24. #ifndef __TYPES__
  25.     #include <Types.h>
  26. #endif
  27.  
  28. #ifndef __WINDOWS__
  29.     #include <Windows.h>
  30. #endif
  31.  
  32. #ifndef __QUICKDRAW__
  33.     #include <Quickdraw.h>
  34. #endif
  35.  
  36. #ifndef __RESOURCES__
  37.     #include <Resources.h>
  38. #endif
  39.  
  40. #ifndef __FONTS__
  41.     #include <Fonts.h>
  42. #endif
  43.  
  44. #ifndef __DIALOGS__
  45.     #include <Dialogs.h>
  46. #endif
  47.  
  48. #ifndef __ERRORS__
  49.     #include <Errors.h>
  50. #endif
  51.  
  52.  
  53.  
  54.  
  55. // Application Includes
  56.  
  57. #ifndef __BAREBONES__
  58.     #include "BareBones.h"
  59. #endif
  60.  
  61. #ifndef __PROTOTYPES__
  62.     #include "Prototypes.h"
  63. #endif
  64.  
  65.  
  66.  
  67.  
  68. // Static prototypes
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. void DoActivate ( EventRecord* theEvent )
  76. {
  77.     Boolean        bActiveFlag = theEvent->modifiers & resumeFlag;
  78.     SInt16        ignoreItem;
  79.     WindowRef    ignoreWindow;
  80.     WindowRef    theWindow = (WindowRef) theEvent->message;
  81.     GrafPtr        savePort;
  82.  
  83.     
  84.     GetPort ( &savePort );
  85.     SetPortWindowPort ( theWindow );
  86.     DialogSelect ( theEvent, &ignoreWindow, &ignoreItem );
  87.     SetPort ( savePort );
  88.     
  89.     return;
  90. }
  91.  
  92.  
  93.  
  94. void DoUpdate ( EventRecord* theEvent )
  95. {
  96.     OSErr            theErr;
  97.     GrafPtr            savePort;
  98.     CGrafPtr        thePort;
  99.     WindowRef        theWindow = (WindowRef) theEvent->message;
  100.     RgnHandle        theRgn;
  101.     
  102.     
  103.     
  104.     theRgn = NewRgn ( );
  105.     theErr = MemError ( );
  106.     if ( theErr )    goto CleanupAndBail;
  107.     
  108.     GetPort ( &savePort );
  109.     SetPortWindowPort ( theWindow );
  110.     BeginUpdate ( theWindow );                    // visRgn temporarily = updateRgn
  111.  
  112.     thePort = GetWindowPort ( theWindow );
  113.     UpdateDialog ( theWindow, thePort->visRgn );
  114.     DisposeRgn ( theRgn );
  115.     
  116.     EndUpdate ( theWindow );                    // restore normal visRgn of grafport
  117.     SetPort ( savePort );
  118.     
  119. CleanupAndBail:
  120.  
  121.     return;
  122. }
  123.  
  124.  
  125.  
  126. void DoContentClick ( WindowRef theWindow, EventRecord* theEvent )
  127. {
  128.     WindowRef    frontWindow;
  129.     
  130.     // If a movable modal is active, ignore click in an inactive 
  131.     // window, otherwise select it or handle the content click.
  132.     
  133.     frontWindow = FrontWindow ( );
  134.     if ( theWindow != frontWindow )
  135.     {
  136.         if ( IsMovableModal ( frontWindow ) )
  137.             SysBeep ( 30 );
  138.         else
  139.             SelectWindow ( theWindow );
  140.     }
  141.     else
  142.     {
  143.         SInt16        itemHit;
  144.         
  145.         if ( DialogSelect ( theEvent, &theWindow, &itemHit ) && itemHit == 1 )
  146.         {
  147.             tThreadedOperationPtr theInfo;
  148.             
  149.             theInfo = (tThreadedOperationPtr) GetWRefCon ( theWindow );
  150.             theInfo->bCancelled = true;
  151.         }
  152.     }
  153.     
  154.     return;
  155.     
  156. } // DoContentClick
  157.  
  158.  
  159.  
  160. void DoDragWindow ( WindowRef theWindow, EventRecord* theEvent )
  161. {
  162.     WindowRef    frontWindow;
  163.     
  164.     
  165.     // If a movable modal is active, ignore click in an inactive 
  166.     // title bar, otherwise let the Window Manager handle it.
  167.     
  168.     frontWindow = FrontWindow ( );
  169.     if ( theWindow != frontWindow && IsMovableModal ( frontWindow ) )
  170.         SysBeep ( 30 );
  171.     else                                
  172.     {
  173.         RgnHandle    theRgn;
  174.         Rect        dragRect;
  175.         
  176.         theRgn = GetGrayRgn ( );
  177.         dragRect = (*theRgn)->rgnBBox;
  178.         DragWindow ( theWindow, theEvent->where, &dragRect );
  179.     }
  180.     
  181.     return;
  182. }
  183.  
  184.  
  185.  
  186.  
  187.  
  188.